var searchCategoryItem = new Array();
searchCategoryItem[0] = "categoryItem1";
searchCategoryItem[1] = "categoryItem2";
searchCategoryItem[2] = "categoryItem3";
searchCategoryItem[3] = "categoryItem4";
searchCategoryItem[4] = "categoryItem5";

var searchCategoryItemName = new Array();
searchCategoryItemName[0] = "기쁨";
searchCategoryItemName[1] = "슬픔";
searchCategoryItemName[2] = "즐거움";
searchCategoryItemName[3] = "놀람";
searchCategoryItemName[4] = "화남";

var searchCategoryItemText = new Array();
searchCategoryItemText[0] = "categoryItemText1";
searchCategoryItemText[1] = "categoryItemText2";
searchCategoryItemText[2] = "categoryItemText3";
searchCategoryItemText[3] = "categoryItemText4";
searchCategoryItemText[4] = "categoryItemText5";

var menuItemSet = new Array();
menuItemSet[0] = "writing";
menuItemSet[1] = "photo";
menuItemSet[2] = "video";
menuItemSet[3] = "music";
menuItemSet[4] = "link";

$(document).ready(function() {
	
	$("#testM").click(function(e){
		if($("#testM").height()==$("#testM").children("div").length*25+38){
			  $("#testM").animate({
			      height:"39px"
			    },200);
			  $("#testM").children("div").animate({
			      height:"0px"
			    },200);
			  $("#testM").children("div").children("span").animate({
			      'font-size':"0px"
			    },5);
			  
			  $("#testM").children("img").attr("src","/images/select_arrow.png");
			  
		}else if($("#testM").height()==39){
			 $("#testM").animate({
			      height:$("#testM").children("div").length*25+38
			    },200);
			 $("#testM").children("div").animate({
			      height:"25px"
			    },200);
			  $("#testM").children("div").children("span").animate({
			      'font-size':"14px"
			    },10);
			  $("#testM").children("img").attr("src","/images/select_arrow_over.png");
		}
		
	});
	
	
	 var spans = $("#testM").children("div");
     $.each(spans, function (i) { 
    	 
    	 	$("#testM").children("div").children("span").eq(i).click(function(e){
    	 		$("#testM").children("span").text($("#testM").children("div").children("span").eq(i).text());
    	 		if($("#testM").children("div").children("span").eq(i).text()=="직접입력"){
    	 			$(".clickWrap_infoInput_email").children("input").eq(1).attr("value","");
    	 			$("#testM").children("img").css("margin-left","50px");
    	 		}else{
    	 			$(".clickWrap_infoInput_email").children("input").eq(1).attr("value",$("#testM").children("div").children("span").eq(i).text());
    	 			$("#testM").children("img").css("margin-left",50-($("#testM").children("div").children("span").eq(i).width()-48)+"px");
    	 		}
    	 	
    	 		
    		});
    	 	
    	 	$("#testM").children("div").eq(i).click(function(e){
    	 		$("#testM").children("span").text($("#testM").children("div").children("span").eq(i).text());
    	 		if($("#testM").children("div").children("span").eq(i).text()=="직접입력"){
    	 			$(".clickWrap_infoInput_email").children("input").eq(1).attr("value","");
    	 			$("#testM").children("img").css("margin-left","50px");
    	 		}else{
    	 			$(".clickWrap_infoInput_email").children("input").eq(1).attr("value",$("#testM").children("div").children("span").eq(i).text());
    	 			$("#testM").children("img").css("margin-left",50-($("#testM").children("div").children("span").eq(i).width()-48)+"px");
    	 		}
    	 		
    		});
     });
     
	
	$(".login_join_content_email_div").click(function(e){
		location.href="clickWrap.do";
	});
	
	$(".custom_radio_service").click(function(e){
		var check = $(".custom_radio_service").attr("src").indexOf("over");
		if(check==-1){
			$(".custom_radio_service").attr("src","/images/radio_over.png");
		}else{
			$(".custom_radio_service").attr("src","/images/radio.png");
		}
		
	});
	
	$(".custom_radio_private").click(function(e){
		var check = $(".custom_radio_private").attr("src").indexOf("over");
		if(check==-1){
			$(".custom_radio_private").attr("src","/images/radio_over.png");
		}else{
			$(".custom_radio_private").attr("src","/images/radio.png");
		}
		
	});
	
	
	$("#headerSetting").click(function(e){
		if($(".settingMap").css("display")=="block"){
			$(".settingMap").fadeOut("fast");
		}else if($(".settingMap").css("display")=="none"){
			
			$(".noticeMap").fadeOut("fast");
			$(".menuMap").fadeOut("fast");
			$(".categoryMap").fadeOut("fast");
			
			$(".settingMap").fadeIn("fast");
		}
		
	});
	
	$("#headerNotice").click(function(e){
		if($(".noticeMap").css("display")=="block"){
			$(".noticeMap").fadeOut("fast");
		}else if($(".noticeMap").css("display")=="none"){
			
			$(".settingMap").fadeOut("fast");
			$(".menuMap").fadeOut("fast");
			$(".categoryMap").fadeOut("fast");
			
			$(".noticeMap").fadeIn("fast");
		}
		
	});
	
	$("#headerMenu").click(function(e){
		if($(".menuMap").css("display")=="block"){
			$(".menuMap").fadeOut("fast");
		}else if($(".menuMap").css("display")=="none"){
			
			$(".settingMap").fadeOut("fast");
			$(".noticeMap").fadeOut("fast");
			$(".categoryMap").fadeOut("fast");
			
			$(".menuMap").fadeIn("fast");
		}
		
	});
	
	$("#headerCategory").click(function(e){
		console.log(e.target);
		if($(".categoryMap").css("display")=="block"){
			for(var i=0; i<searchCategoryItem.length; i++){
				if(e.target.id==searchCategoryItem[i]){
					$("#changeText").html(searchCategoryItemName[i]);
					return;
				}
			}
			if(e.target.nodeName!="SPAN" && e.target.nodeName!="INPUT" && e.target.id!="categoryMap" && e.target.id!="categoryView"){
				$(".categoryMap").fadeOut("fast");
			}else if(e.target.nodeName=="SPAN"){
				for(var i=0; i<searchCategoryItemText.length; i++){
					if(e.target.id==searchCategoryItemText[i]){
						$("#changeText").html(searchCategoryItemName[i]);
						return;
					}
				}
				
			}
		}else if($(".categoryMap").css("display")=="none"){
			
			$(".settingMap").fadeOut("fast");
			$(".noticeMap").fadeOut("fast");
			$(".menuMap").fadeOut("fast");
			
			$(".categoryMap").fadeIn("fast");
		}
		
	});
	
	$("#writingCancel").click(function(e){
		$("#writingView").css("display","none");
		$("#topNav").css("display","block");
	});
	
	$("#writingUpload").click(function(e){
		
		if($("#writingView").css("display")=="block"){
			$("#writingView").css("display","none");
		}else{
			$("#writingView").css("display","block");
		}
		
		
	});
	
	$("#searchCancel").click(function(e){
		$("#searchView").css("display","none");
		$("#topNav").css("display","block");
	});
	
	$("#search").click(function(e){
		$("#searchView").css("display","block");
		$("#topNav").css("display","none");
	});
	
	$(".photoUpdateContent").click(function(e){
		document.getElementById('photoFile').click();
	});	
	
	$(".searchCategorySelectItem").click(function(e){
		var nodeId = e.target.id;
		var check = false;
		for(var i=0; i<searchCategoryItem.length; i++){
			if(searchCategoryItem[i]==nodeId){
				check=true;
			}
		}
		
		if(check){
			console.log($("#c"+nodeId).is(":checked"));
			if($("#c"+nodeId).is(":checked")==false){
				$("#c"+nodeId).prop("checked",true);
				$("#"+nodeId).css("background","#ebebeb");
			}else if($("#c"+nodeId).is(":checked")==true){
				$("#c"+nodeId).prop("checked",false);
				$("#"+nodeId).css("background","white");
			}
			
		}
		
	});
	
	$("#writingButton").click(function(e){
		if($(".writingCategory").css("display")=="block"){
			$(".writingCategory").fadeOut("fast");
		}else if($(".writingCategory").css("display")=="none"){
			$(".writingCategory").fadeIn("fast");
		}
	});
	
	 var writingCategory = $(".writingCategory").children("span");
     $.each(writingCategory, function (i) {
    	 $(".writingCategory").children("span").eq(i).click(function(e){
    		 $("#writingButton").text($(".writingCategory").children("span").eq(i).text());
    		 $(".writingCategory").fadeOut("fast");
    	 });
    	 
     });
	
/*	for(var i=0; i<menuItemSet.length; i++){
		console.log(menuItemSet[i]);
		$("#"+menuItemSet[i]).mouseover(function(e){
			console.log(menuItemSet[i]+"");
			menuChange(menuItemSet[i]+"","over");
			
		});
		
		$("#"+menuItemSet[i]).mouseout(function(e){
			menuChange(menuItemSet[i]+"","out");
		});
		
	}*/
	
	$("#"+menuItemSet[0]).mouseover(function(e){
		menuChange(menuItemSet[0]+"","over");
		
	});
	
	$("#"+menuItemSet[0]).mouseout(function(e){
		menuChange(menuItemSet[0]+"","out");
	});
	
	
	
	$("#"+menuItemSet[1]).mouseover(function(e){
		menuChange(menuItemSet[1]+"","over");
		
	});
	
	$("#"+menuItemSet[1]).mouseout(function(e){
		menuChange(menuItemSet[1]+"","out");
	});
	
	
	
	$("#"+menuItemSet[2]).mouseover(function(e){
		menuChange(menuItemSet[2]+"","over");
		
	});
	
	$("#"+menuItemSet[2]).mouseout(function(e){
		menuChange(menuItemSet[2]+"","out");
	});
	
	
	$("#"+menuItemSet[3]).mouseover(function(e){
		menuChange(menuItemSet[3]+"","over");
		
	});
	
	$("#"+menuItemSet[3]).mouseout(function(e){
		menuChange(menuItemSet[3]+"","out");
	});
	
	
	
	$("#"+menuItemSet[4]).mouseover(function(e){
		menuChange(menuItemSet[4]+"","over");
		
	});
	
	$("#"+menuItemSet[4]).mouseout(function(e){
		menuChange(menuItemSet[4]+"","out");
	});
	
	/*$(".login_button").click(function(e){
		if($(".login_fail_msg").css("visibility")=="visible"){
			$(".login_fail_msg").css("visibility","hidden");
		}else if($(".login_fail_msg").css("visibility")=="hidden"){
			$(".login_fail_msg").css("visibility","visible");
		}
		
	});*/
	
	$(".login_question").click(function(e){
		if($(".login_question_account_div").css("visibility")=="visible"){
			$(".login_question_account_div").css("visibility","hidden");
			$(".login_question").attr("src","/images/login/login_question.png");
		}else if($(".login_question_account_div").css("visibility")=="hidden"){
			$(".login_question_account_div").css("visibility","visible");
			$(".login_question").attr("src","/images/login/login_question_close.png");
		}
		
		
	});
	
/*	$("#contentSubmenu").click(function(e){
		
		
		
		
		
		
		
		if($("#submenu").css("display")=="block"){
			$("#contentSubmenu").parent().children("div").css("display","none");
		}else if($("#submenu").css("display")=="none"){
			$("#contentSubmenu").parent().children("div").css("display","block");
		}
		
	});*/
	
	
	
	
});

function subMenuView(spanInfo){
	
	if($(spanInfo).parent().children("div").css("display")=="block"){
		$(spanInfo).parent().children("div").css("display","none");
	}else if($(spanInfo).parent().children("div").css("display")=="none"){
		$(spanInfo).parent().children("div").css("display","block");
	}
	
}

function menuChange(id,type){
	if(type=="over"){
		var src = $("#"+id).children("img").attr("src").split(id);
		src = src[0] + id+"_over.png";
		$("#"+id).children("img").attr("src",src);
	}else if(type=="out"){
		var src = $("#"+id).children("img").attr("src").split(id);
		src = src[0] + id+".png";
		$("#"+id).children("img").attr("src",src);
	}
}

function writingSubChange(str){
	$("#writingCategoryView").css("display","none");
	/*$("#writingButton").attr("value",str);*/
	$("#writingButton").text(str);
}
